<#-- TODO: 1. check all the code , use label value in the text model-->
<#-- TODO: 2. rename _gridModel, _namePrefix to a normal case -->
<#--NOTICE: the parameter 'name' is the short name -->
<#function _getValue name>
	<#return tag.getValue(action, name, _gridModel, _gridItem, _namePrefix)>
</#function>

<#function _getPageElement name>
	<#return tag.getPageElement(ps, name, _gridModel, _namePrefix)>
</#function>

<#include 'bscommon.control.ftl'>

<#--
	@ModelField
-->
<#macro text name='' label='' textModel=false required=false show=true type='text' value='' defaultValue='' clazz='' style='' mask='' placeholder='' width=0 colspan=1 positionCol=-1 id=''>
	<@control type=type id=id name=name value=value defaultValue=defaultValue width=width label=label
		clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if type=='number'>
			<#local type='text'>
			<#local genericType='number'>
		</#if>
		<#if style != ''>
			<#local height = tag.css(0, style,'height')>
		</#if>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		
		<input type="${type}" name="${name}" <#if genericType??>genericType="${genericType}"</#if> <#if prequired>required=true</#if> <#t>
			<#if height?exists && height gt 4> style="height:${height-4}px" </#if><#t>
			class="form-control <#if genericType??>${genericType}<#else>${type}</#if>"<#t>
			<#if placeholder!=''> placeholder="${placeholder}"</#if><#t>
			<#if mask!=''>mask="${mask}"</#if> value="${fn.s(val,name)}"/><#t>
	</@control>
</#macro>

<#--
	@ModelField
-->
<#macro number name='' label='' textModel=false required=false show=true value='' defaultValue='' clazz='' style='' width=0 colspan=1 positionCol=-1 id=''>
	<@text name=name type='number' value=value defaultValue=defaultValue id=id label=label 
		clazz=clazz style=style required=required width=width colspan=colspan positionCol=positionCol show=show textModel=textModel/>
</#macro>

<#--
	@ModelField
-->
<#macro password name='' label='' textModel=false required=false show=true value='' defaultValue='' clazz='' style='' width=0 colspan=1 positionCol=-1 id=''>
	<@text name=name type='password' value=value defaultValue=defaultValue id=id label=label
		 clazz=clazz style=style required=required width=width colspan=colspan positionCol=positionCol show=show textModel=textModel/>
</#macro>

<#--
	@ModelField
-->
<#macro hidden name='' value='' defaultValue='' id=''>
	<#if value?string==''>
		<#local value=_getValue(name)>
	</#if>
	<#local _pageElement = _getPageElement(name)>
	<#if !_pageElement?is_boolean>
		<#local tmp = _pageElement.setLabel('')>
	</#if>
	<@control type='hidden' id=id name=name value=value defaultValue=defaultValue clazz='hidden hide'>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<input type="hidden" name="${name}" value="${fn.s(val,name)}"/><#t>
	</@control>
</#macro>

<#--
	@ModelField
-->
<#macro file name label='' textModel=false required=false show=true value='' defaultValue='' clazz='' style='' width=0 colspan=1 positionCol=-1 id=''>
	<#if value?is_string && value==''>
		<#local value=_getValue(name + 'FileName')>
	</#if>
	<#if value != ''>
		<#assign viewFilePath = fn.replaceAction(actionPath, 'viewFile')>
		<#assign fileDisplayName = tag.formatFileName(value)>
		<#local labelValue= '<a href="' + fn.link(viewFilePath) + '?name=' + value + '" title="' + fileDisplayName + '" target="_blank">'
						+ fileDisplayName + '</a>'>
	<#else>
		<#local labelValue=''>
	</#if>
	<@control type='file' id=id name=name value=value defaultValue=defaultValue width=width label=label labelValue=labelValue
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if !pElement?is_boolean> <#-- TODO: isNewPE -->
			<#local tmp = pElement.addExtraName(name + 'FileName', _namePrefix!, _oldNamePrefix!)>
		</#if>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<div class="jbox jfile"><#t>
			<span class="file_ctn">
				<span class="file_label"><em class="file_selector">+</em><span class="file_name">
					<#if !pshow || val == ''>
						<@i18n name="file.add.label"/>
					</#if>
				</span></span>
				<#if !ps.isMock()>
					<input type="file" name="${name}" <#if prequired>required=true</#if> class="jinput file" onchange="showFileRemoveLink(this)"/>
				<#else>
					<input type="hidden" name="${name}"/>
				</#if>
			</span>
			<div class="file_ctn_old">
			<#if pshow && val != ''>
				<span>
					${labelValue}
					<input type="hidden" name="${name}FileName" value="${val}"/>
				</span>
				<a href="javascript:void(0)" onclick="$(this).parent().html('')"><em class="tinyClose"></em></a>
			</#if>
			</div>
		</div>
	</@control>
</#macro>

<#--
	@ModelField
-->
<#macro textarea name label='' textModel=false required=false show=true value='' defaultValue='' clazz='' style='' height=0 width=0 colspan=1 positionCol=-1 id=''>
	<@control type='textarea' id=id name=name value=value defaultValue=defaultValue width=width label=label
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#local pheight=height>
		<#local _pageElement = _getPageElement(name)>
		<#if !_pageElement?is_boolean>
			<#local pheight=_pageElement.extraParams?if_exists.height!pheight>
		</#if>
		<#if style != ''>
			<#local pheight = tag.css(pheight, style,'height')>
		</#if>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<textarea id="${id}" name="${name}" class="form-control" <#if pheight gt 2> style="height:${pheight-2}px" </#if>><#t>
			${fn.s(val,name,false)}<#t>
		</textarea><#lt>
	</@control>
</#macro>

<#macro pagination name='' pageInfo=[] paginationClazz=''>
	<#local isMock = ps.isMock() && name!=''>
	<#if isMock>
		<div class="jpagination stdEle" fullName='${name}' uiType='pagination'>
		<#local pageInfo = fn.newModel('com.googlecode.cswish.model.PageInfo')>
	</#if>
	
	<ul class="pagination">
	  <li><a href="#">&laquo;</a></li>
	  <li><a href="#">1</a></li>
	  <li><a href="#">2</a></li>
	  <li><a href="#">3</a></li>
	  <li><a href="#">4</a></li>
	  <li><a href="#">5</a></li>
	  <li><a href="#">&raquo;</a></li>
	</ul>
	
	<#if isMock>
		</div>
	</#if>
</#macro>

<#--
	@ModelField
-->
<#macro select name='' label='' textModel=false required=false show=true value='' defaultValue='' collection=[] property="id" labelProperty="name"
	showMoreIcon=true multiple=false width=0 clazz='' style='' colspan=1 positionCol=-1 id=''>
	<#if !(collection?is_enumerable)>
		<#local collection = fn.val(action,collection)![]>
	</#if>
	<#if textModel && (!_gridModel?? || _gridModel != 6)>
		<#local initData = 'null'>
	<#else>
		<#local initData = '{maxPageNo:1,data:' + fn.json(collection, property + ',' + labelProperty, false, name) + '}'>	
	</#if>
	
	<#local labelValue = ''>
	<#if value == ''>	<#-- combobox can't get the correct value and label because we don't pass the collection parameter, so, calculate here-->
		<#local value = _getValue(name)>
	</#if>
	<#if value?is_string && value == ''>
		<#local value = defaultValue>
	</#if>
	<#local labelValue = tag.getLabelValue(collection, property, labelProperty, value)!>
	<#local value = fn.s(value, name, false)>
	
	<#if !_comboboxType?exists || _comboboxType == ''>
		<#assign _comboboxType = 'select'>
	</#if>
	<@combobox name=name value=value defaultValue=defaultValue labelValue=labelValue id=id property=property labelProperty=labelProperty
		enableFreeText=false enableDynamicName=false initData=initData showMoreIcon=showMoreIcon multiple=multiple
		width=width label=label clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel/>
	<#local tmp = pElement.addExtraParams('collection', collection)>
</#macro>

<#--
	@ModelField
-->
<#macro enumselect name label='' textModel=false required=false show=true model='' value='' defaultValue='' width=0 clazz='' style='' colspan=1 positionCol=-1 id=''>
	<#assign collection=fn.enumList(model, name)>
	<#if !_comboboxType?exists || _comboboxType == ''>
		<#assign _comboboxType = 'enumselect'>
	</#if>
	<@select name=name collection=collection value=value defaultValue=defaultValue id=id property="key" labelProperty="value" width=width label=label
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel/>
</#macro>

<#--
	@ModelField
	load the data from dictionary table
	FIXME: <#local labelValue=''>, addLink
-->
<#macro dictselect name label='' type='' textModel=false required=false show=true value='' defaultValue='' width=0 clazz='' style='' colspan=1 positionCol=-1 id=''>
	<#if !_comboboxType?exists || _comboboxType == ''>
		<#assign _comboboxType = 'dictselect'>
	</#if>
	
	<#local value = _getValue(name)>
	<#if value?exists>
		<#local labelValue=fn.service('espirit.eap.manager.dictionary').getNameByTypeValue(type, value)!>
	<#else>
		<#local value = ''>
	</#if>
	
	<#if textModel>
		<#local addUrl = ''>
	<#else>
		<#local addUrl = fn.linkModel('espirit.eap.manager.dictionary', '_add') + '?model.type=' + type>
	</#if>

	<@modelselect name=name value=value defaultValue=defaultValue id=id width=width label=label enableInitData=false
		labelValue=labelValue model='espirit.eap.manager.dictionary' property="value" labelProperty="name" filterProperty='type' filter=type
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel addUrl=addUrl/>
</#macro>

<#--
	@ModelField
/**
 * Display properties: name, labelName, value, labelValue, property, labelProperty 
 	(
 		NOTICE1: label is another generic concept
 		NOTICE2: nested name affects the 'name' but don't affect labelName, so, they are different in the self page definition
 	)
 * Load remote data properties: initData, url, property, labelProperty
 *
 * value <== getValue(name)
 * labelValue <== getValue(labelName)
 *      the complex logic is: labelName <== guest the nested label property througn the name & property & labelProperty when label name is empty
 *		NOTICE: assign the labelValue manually if the labelName doesn't exist (such as label value comes from the dictionary table)
 *
 * @param PageInfo initData the initialized value of the first pagination data, the other data gets through 'url'
 * @param String url load the context through it asynchronously
 * @param boolean enableDynamicName in the free text model, name is same with label property,
 * 		but, most of case, label property uses the short name that means the full label property is 'name + labelProperty'.
 * @parm String affect notify the affected element when value is changed
 */-->
<#macro combobox name='' labelName='' property="id" labelProperty="name" value='' labelValue='' defaultValue='' initData='null'
 	label='' textModel=false required=false show=true url='' addUrl='' model=''
	onselect='null' affect='' enableFreeText=false showMoreIcon=true multiple=false enableDynamicName=false width=0 clazz='' style='' colspan=1 positionCol=-1 id=''>
	<#assign _labelName = labelName>
	<#if labelValue?is_string && labelValue == ''>
		<#assign _labelName=tag.getComboboxDisplayName(name, labelName, property, labelProperty, enableFreeText && enableDynamicName)>
		<#local labelValue=tag.getComboboxDisplayValue(action, name, labelName, property, labelProperty, enableFreeText, value, _gridModel, _gridItem, _namePrefix)>
	</#if>
	<#if value?is_string && value == ''>	<#-- FIXME: why caculates the value here? -->
		<#local value=_getValue(name)>
	</#if>

	<#if !_comboboxType?exists || _comboboxType == ''>
		<#assign _comboboxType = 'combobox'>
	</#if>
	<@control id=id name=name type=_comboboxType value=value defaultValue=defaultValue labelValue=labelValue width=width label=label
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
			<#if _labelName != ''>
				<#local _labelName = _namePrefix + _labelName>
			</#if>
		</#if>
		<#-- record the additional names, TODO: check isNewPE for better performance -->
		<#if (!pElement?is_boolean) && _labelName!=''>
			<#local tmp = pElement.addExtraName(_labelName, '', _oldNamePrefix!)>
			<#local tmp = pElement.addExtraParams('labelProperty', labelProperty)>
		</#if>
		
		<select class="form-control" name=${name}>
			<option>1</option>
			<option>2</option>
			<option>3</option>
			<option>4</option>
			<option>5</option>
		</select>
	</@control>

	<#assign _labelName = ''>
	<#assign _comboboxType = ''>
</#macro>

<#--
	@ModelField
-->
<#macro modelselect name labelName='' property='id' labelProperty='name' model='' label='' value='' labelValue='' defaultValue=''
	textModel=false required=false show=true addBlankItem=false isSelectBlankItem=false exProperty='' filterProperty='' filter=''
	onselect = 'null' affect='' enableFreeText=false enableDynamicName=false enableInitData=true showMoreIcon=true multiple=false addUrl='' showAddLink=true
	width=0 clazz='' style='' colspan=1 positionCol=-1 id=''>
	<#local _pageElement = _getPageElement(name)>
	<#if !_pageElement?is_boolean>
		<#local textModel = _pageElement.textModel!textModel>
		<#local addBlankItem = _pageElement.extraParams?if_exists.addBlankItem!addBlankItem>
		<#local showAddLink = _pageElement.extraParams?if_exists.showAddLink!showAddLink>
	</#if>
	
	<#if addBlankItem>
		<#assign sAddBlankItem = 'ALL'>
	<#else>
		<#assign sAddBlankItem = ''>
	</#if>
	
	<#assign url = ''>
	<#if textModel && (!_gridModel?? || _gridModel != 6)>	<#-- special logic for advance search -->
		<#assign initData = 'null'>
		<#local showAddLink = false>
	<#else>
		<#if fn.hasVal(value) && enableInitData>
			<#assign modelInfo = fn.service('espirit.eap.pagelayout.model', 'searchModelList', 
				[model,'id',labelProperty,exProperty,'',sAddBlankItem,isSelectBlankItem?exists,1,10,statCount?default('true')])>
			<#if exProperty == ''>
				<#assign initProperty = 'totalCount,maxPageNo,data.id,data.' + labelProperty>
			<#else>
				<#assign initProperty = 'totalCount,maxPageNo,data.id,data.' + labelProperty + ',data.' + exProperty>
			</#if>
			<#assign initData = fn.json(modelInfo, initProperty, false, '')>
		<#else>
			<#assign initData = 'null'>
		</#if>
		<#assign urlParam = 'name=' + model + '&property=' + property + '&labelProperty=' + labelProperty + '&exProperty=' + exProperty 
			+ '&addBlankItem=' + sAddBlankItem + '&isSelectBlankItem=' + isSelectBlankItem?string + '&statCount=' + statCount?default('true')>
		<#if filterProperty != ''>
			<#assign urlParam = urlParam + '&filterProperty=' + filterProperty + '&filter=' + filter>
		</#if>
		<#assign url = '/espirit/eap/pagelayout/model.searchModelList.html?' + urlParam>
		
		<#if showAddLink && !textModel && model!=''>
			<#-- TODO: build link here? verify the link in the combobox? -->
			<#if addUrl == ''>
				<#local addUrl = fn.linkModel(model, '_add')>
			</#if>
			<#if addUrl != ''>
				<#assign hasPermission = fn.service('loginUser').hasLinkPermission(addUrl)>
				<#if !hasPermission>
					<#assign addUrl = ''>
				</#if>
			</#if>
		</#if>
	</#if>
	
	<#if !_comboboxType?exists || _comboboxType == ''>
		<#assign _comboboxType = 'modelselect'>
	</#if>
	<@combobox name=name labelName=labelName model=model url=url addUrl=addUrl value=value defaultValue=defaultValue labelValue=labelValue id=id property=property labelProperty=labelProperty
		onselect=onselect affect=affect enableFreeText=enableFreeText enableDynamicName=enableDynamicName initData=initData showMoreIcon=showMoreIcon multiple=multiple
		width=width label=label clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel/>
</#macro>

<#--
	@ModelField
-->
<#macro autosearch name property="id" labelProperty="name" value='' defaultValue='' labelValue=''
	label='' textModel=false required=false show=true model='' addBlankItem=false isSelectBlankItem=false
	onselect = 'null' width=0 clazz='' style='' colspan=1 positionCol=-1 id=''>
	<#if !_comboboxType?exists || _comboboxType == ''>
		<#assign _comboboxType = 'autosearch'>
	</#if>
	<@modelselect name=name model=model value=value defaultValue=defaultValue labelValue=labelValue addBlankItem=addBlankItem isSelectBlankItem=isSelectBlankItem
		id=id property=property labelProperty=labelProperty
		onselect=onselect enableFreeText=true enableInitData=false showMoreIcon=false
		width=width label=label clazz=clazz style=style required=required colspan=colspan positionCol=positionCol  show=show textModel=textModel/>
</#macro>

<#--
	@ModelField
	property,labelProperty is used by the collection, see checkboxlist
-->
<#macro checkbox name label='' textModel=false required=false show=true collection=[] property="id" labelProperty="name" fieldValue='true'
	value='' defaultValue='' clazz='' style='' width=0 colspan=1 positionCol=-1 id=''>
	<#if value?string==''>
		<#local value=_getValue(name)>
	</#if>
	<#if !(collection?is_enumerable)>
		<#local collection = fn.val(action,collection)![]>
	</#if>
	<#if textModel>
		<#list collection as item>
			<#if itemProperty==value>
				<#local value=item[labelProperty]>
				<#break>
			</#if>
		</#list>
	</#if>
	<@control type='checkbox' id=id name=name value=value defaultValue=defaultValue width=width label=label
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<#if collection?size gt 0>
			<#list collection as item>
				<#assign itemProperty = item[property]>
				<div class="jbox checkbox"><input type="checkbox" class="jcheckbox" name="${name}" value="${itemProperty}" <#if fn.contains(val,itemProperty)>checked="checked"</#if>/> ${item[labelProperty]}</div>
			</#list>
		<#else>
			<label class="checkbox-inline"><input type="checkbox" class="jcheckbox" name="${name}" value="${fieldValue}" <#if fn.equals(fieldValue, val)>checked="checked"</#if>/></label>
		</#if>
	</@control>
</#macro>

<#--
	@ModelField
	name: input name
	model, property, labelProperty: the checkbox list
	list: the checked values
-->
<#macro checkboxlist name label='' textModel=false required=false show=true model='' list='' clazz='' style='' property="id" labelProperty="name" width=0 colspan=1 positionCol=-1 id=''>
	<@control type='checkboxlist' id=id name=name value=value defaultValue=defaultValue width=width
		 label=label clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<#assign collection = fn.service('espirit.eap.pagelayout.model', 'searchModelList', [model,'','','','','',false,1,20,true]).data>
		<#assign checkedValue = _getValue(list)![]>
		<#if collection?size gt 0>
			<#list collection as item>
				<#assign itemProperty = item[property]!>
				<#assign checked = fn.contains(checkedValue, itemProperty)/>
				<div class="jbox checkbox"><input type="checkbox" class="jcheckbox" name="${name}" value="${itemProperty}" <#if checked>checked="checked"</#if>/> ${item[labelProperty]!}</div>
			</#list>
		<#else>
			<div class="jbox checkbox"><input type="hidden" name="${name}"></div>
		</#if>
	</@control>
</#macro>

<#--
	@ModelField
-->
<#macro radio name label='' textModel=false required=false show=true collection=[] property="id" labelProperty="name" fieldValue=''
	value='' defaultValue='' clazz='' style='' width=0 colspan=1 positionCol=-1 id=''>
	<#if value?string==''>
		<#local value=_getValue(name)>
	</#if>
	<#if !(collection?is_enumerable)>
		<#local collection = fn.val(action,collection)![]>
	</#if>
	<#if textModel>
		<#list collection as item>
			<#if itemProperty==value>
				<#local value=item[labelProperty]>
				<#break>
			</#if>
		</#list>
	</#if>
	<@control type='radio' id=id name=name value=value defaultValue=defaultValue width=width label=label
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<#if collection?size gt 0>
			<#list collection as item>
				<#assign itemProperty = item[property]>
				<div class="jbox radio"><input type="radio" class="jradio" name="${name}" value="${fn.s(itemProperty,property)}" <#if value?string==itemProperty>checked="checked"</#if>/> ${item[labelProperty]!}</div>
			</#list>
		<#else>
			<label class="checkbox-inline"><input type="radio" class="jradio" name="${name}" value="${fn.s(fieldValue,'')}" <#if fieldValue==val>checked="checked"</#if>/></label>
		</#if>
	</@control>
</#macro>

<#--
	@ModelField
-->
<#macro date name label='' textModel=false required=false show=true value='' defaultValue='' format='' showRange=false showDate=true id='' clazz='' style='' width=0 colspan=1 positionCol=-1 id=''>
	<#if format != '' && textModel>		<#--TODO: check pElement? -->
		<#if _gridModel?exists && _gridModel gt 0>
			<#local value=fn.val(_gridItem, name, _namePrefix + name)!''>
		<#else>
			<#local value=_getValue(name)>
		</#if>
		<#local value = fn.format(value, format)>
	</#if>

	<@control type='date' id=id name=name value=value defaultValue=defaultValue width=width label=label
		 clazz=clazz style=style required=required colspan=colspan positionCol=positionCol show=show textModel=textModel>
		<#if _namePrefix??>
			<#local name = _namePrefix + name>
		</#if>
		<#if val?is_enumerable><#assign val=val[0]></#if>
		<#if _gridModel?exists && _gridModel=6>
			<#-- special logic for advanced search-->
			<#local showRange = true>
		</#if>
		<#if format == ''>
			<#local format = 'yyyy-MM-dd'>
		<#else>
			<#local val = fn.format(val, format)>
		</#if>
		<#assign sval = fn.s(val, name)>
		<#if showRange>
			<input id="${id}" type="date" genericType="date" class="form-control" 
				name="${name}"  value="${sval}"/><#t>
			
			<span class="dateRangeLabel"><@i18n name='button.menu.to'/></span>
			<#local val2=_getValue(name+'2')>
			<#assign sval2 = fn.s(val2, name+'2')>
		</#if>
		<input id="${id}" type="date" genericType="date" class="form-control" style="cursor:pointer" 
			<#if showRange>name="${name}2" value="${sval2}"<#else>name="${name}" value="${sval}"</#if><#if prequired> required=true</#if>
		/><#t>
	</@control>
</#macro>

<#macro button label='' name='' onclick='' clazz='' style='' url='' showMoreIcon=false id='' positionCol=-1>
	<#local shortName = tag.getShortName(name)>
	<#local _pageElement = _getPageElement(shortName)>
	
	<#assign hasPermission = true>
	<#assign pcheckPermission = !ps.isMock()>
	<#if pcheckPermission>
		<#-- TODO: guess the url according to the method name when url is empty?-->
		<#if url != ''>
			<#local url = fn.linkNoBase(url, true)>
			<#assign hasPermission = fn.service('loginUser').hasLinkPermission(url, false)>
		</#if>
	</#if>
	
	<#if hasPermission>
	<@control id=id name=shortName type='button' clazz=clazz positionCol=positionCol>
		<#if onclick == ''>
			<#local onclick='openMainTabFromBtn(this, \'${base}${url}\')'>
		</#if>
		
		<button<#if id!=''> id="${id}"</#if> type='button' class="btn btn-default ${clazz} stdEle"<#if positionCol != -1> positionCol=${positionCol}</#if><#if style!=''> style="${style}"</#if>
			name='${shortName}' fullName='${name}' onclick="${fn.quote(onclick)}" onkeypress="clickOnEnter(event, this)" tabindex='0'><@i18n name=label/></button>
		
	</@control>
	</#if>
</#macro>

<#macro imgbutton name='' clazz='' onclick=''>
	<span class="${clazz!}" fullName='${name}' onclick='${onclick}'><em></em></span>
</#macro>

<#macro link name='' label='' url='' clazz='' style='' onclick='' positionCol=-1 id=''>
	<#assign isMock = ps.isMock()>
	<#if isMock || positionCol != -1 || style != ''>
	<span class="stdEle ${clazz} jlink" name='${tag.getShortName(name)}' fullName='${name}' style="${style}" uiType='link' positionCol='${positionCol}' <#if id!=''>id="${id}"</#if>>
	</#if>
		<#local href = tag.formatLink(url, ps, false)>
		<#if href != ''>
			<a href="${href}" class="label"<#if onclick!=''> onclick="${onclick}"</#if>>${action.getText(label)}</a>
		</#if>
	<#if isMock>
	</span>
	</#if>
</#macro>

<#macro linkedbutton name='' label='' show=true image='' url='' width=25 colspan=1 id=''>
	<#local shortName = tag.getShortName(name)>
	<@control id=id name=shortName type='linkedbutton' width=width label=label
		 clazz=clazz required=false colspan=colspan positionCol=positionCol show=show textModel=false>
		<#local url = fn.linkNoBase(url,true)>
		<#assign hasPermission = fn.service('loginUser').hasLinkPermission(url, false)>
		<#if hasPermission>
			<#local imagePathPrefix = tag.getImagePathPrefix('')>
			<a href="javascript:void(0)" onclick="submitImageColumnRequest(event,'${base}${url}',this);" class="linkIconCtn" name='${shortName}' fullName='${name}'>
				<img class="linkIcon" originalsrc="${imagePathPrefix}${image}" <#if val !=''>src="${tag.formatImagePath(image, fn.s(val, name))}"</#if>>
			</a>
		</#if>
	</@control>
</#macro>

<#--
	@ModelField
	value,labelValue is validated only when textModel is true
-->
<#macro i18n name='' locale='' label='' textModel=true required=false show=true clazz='' style='' width=0 value='' labelValue='' positionCol=-1>
	<#if textModel>
		<#if label==''>
			 <#if style!=''><span style="${style}"></#if>${action.getTextByLocale(name, locale)}<#if style!=''></span></#if><#t>
		<#else>
			<div class="j-form-item ${clazz} stdEle" <#if style!=''>style="${style}"</#if> fullName="${name}" uiType="i18n">
				<label class="label">${action.getTextByLocale(label, locale)}</label>
				<span class="span i18n">${(fn.val(action, name)?if_exists.name)!''}</span>
			</div>
		</#if>
	<#else>
		<#assign _comboboxType = 'i18n'>
		<#if label!=''><#local label=action.getTextByLocale(label, locale)></#if>
		
		<@text name=name + '.name' label=label clazz=clazz value=labelValue style=style width=width required=required/>
		
		<#if _gridModel??>
			<#if (_gridModel==2 || _gridModel==3)>
				<#local idName = name + '.id'>
			<#else>
				<#local idName = _namePrefix + name + '.id'>
			</#if>
			<#local tmp = ps.addHiddenElement([_namePrefix + name + '.id'])>
			<#if ps.isMock()>
				<script>PageUtil.setElementFullName('${_namePrefix + name + '.name'}','${_namePrefix + name}')</script>
			</#if>
		<#else>
			<#local idName = name + '.id'>
		</#if>
		
		<input type="hidden" name="${idName}"  value="${_getValue(name + '.id')}"/>
	</#if>
</#macro>

<#macro label name='' clazz='' style='' length=0 value='' positionCol=-1>
	<div name='${tag.getShortName(name)}' fullName='${name}' uiType="label" class="${clazz} jlabel label stdEle<#if value?length == 0> empty</#if>"<#rt>
		<#if value=='' && fn.isValidName(name)>
			<#local value=_getValue(name)>
		</#if>
		<#if style!=''> style='${style}'</#if><#if positionCol != -1> positionCol=${positionCol}</#if> uiType="label"><#lt>
		<#if length!=0 && value?length gt length>
			<a title="${value}">${value?substring(0, length)}...</a>
		<#else>
			${value}
		</#if>
	</div>
</#macro>

<#--
@param type block,line,page
-->
<#macro break type='line' name=''>
	<#if type=='line'>
		<#local clazz = 'line-break'>
	<#elseif type=='block'>
		<#local clazz = 'block-break'>
	<#elseif type=='page'>
		<#local clazz = 'page-break'>
	</#if>
	<div name='${tag.getShortName(name)}' fullName='${name}' class="${clazz} separator stdEle"></div>
</#macro>

<#assign tmp = ps.safeContext().addCssCategory('bscommon')>
<@inject name='bscommon' point='header' type='html' priority=10 once=true>
	<@css src="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" prefix="._bscommon"/>
	<@css src="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" prefix="._bscommon"/>
	<@script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"/>
	<@script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"/>
	<@script src="/static/espirit/scripts/bs.js" _priority=priority/>
</@inject>